package com.test.test02;

import java.util.Properties;

/**
 * @Description TODO(这里用一句话描述这个类的作用)
 *
 * @author liuqinghua
 * @date 2025-10-11
 */
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

public class NacosConfigExample {
    public static void main(String[] args) throws NacosException {
        String serverAddr = "172.16.121.205:8848"; // Nacos服务器地址
        String dataId = "upms-service.properties"; // 配置的dataId
        String group = "DEFAULT_GROUP"; // 配置的group，默认为DEFAULT_GROUP
        Properties properties = new Properties();
        properties.put("serverAddr", serverAddr); // 设置Nacos服务器地址
        // 可以设置用户名和密码，如果启用了Nacos的安全模块
        properties.put("username", "nacos");
        properties.put("password", "nacos");
        properties.put("type", "properties");
        String namespace = "991ebeae-4a8f-4ecd-8cad-22d79cc7561b";
        properties.put("namespace", namespace);
        ConfigService configService = NacosFactory.createConfigService(properties);
        configService.publishConfig(dataId, group, "name=zs\nage=20");
        String content = configService.getConfig(dataId, group, 5000); // 获取配置内容，5000ms超时时间
        System.out.println(content); // 打印配置内容
    }
}
